/*
#Copyright (c) 2013, Philippe Bordron <philippe.bordron@gmail.com>
#
# This file is part of SIPPER.
#
# DCC is free software: you can redistribute it and/or modify
# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU LESSER GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# along with SIPPER.  If not, see <http://www.gnu.org/licenses/>
*/
package combi.wip.utils;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;

public class OrdrePartielInclusionChemins implements OrdrePartiel<List<String>> {

	@Override
	public boolean isEqual(List<String> o1, List<String> o2) {
		return o1.equals(o2);
	}

	@Override
	public boolean isGreatherThan(List<String> o1, List<String> o2) {
		return sousChemin(o2,o1);
	}

	@Override
	public boolean isLowerThan(List<String> o1, List<String> o2) {
		return sousChemin(o1,o2);
	}

	@Override
	public List<String> getFakeRoot() {
		// TODO Auto-generated method stub
		return new LinkedList<String>();
	}


	//l1 sous chemins de l2
	private boolean sousChemin (List<String> l1, List<String> l2)
	{
		//System.err.print(l1 + " sous chemin de " + l2 + "? ");
		ListIterator<String> it2 = l2.listIterator();
		ListIterator<String> it1 = l1.listIterator();
		boolean ok = true;
		if (l1.isEmpty())
		{
			//System.err.println(true);
			return true;
		}
		if(l2.isEmpty())
		{
			//System.err.println(false);
			return false;
		}
		while(it2.hasNext() && ok)
		{
			ok = !l1.get(0).equals(it2.next());
		}
		ok = true;
		it2.previous();
		while(it1.hasNext() && it2.hasNext() && ok)
		{
			ok= it1.next().equals(it2.next());
		}
		if (!it1.hasNext() && ok)
		{
			//System.err.println(true);
			return true;
		}
		//System.err.println(false);
		return false;
	}
}
